{% extends 'course/base.html' %}
{% load staticfiles %}
{% block content %}
        <!-- Page Heading -->
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">
                    Exams
                    <small></small>
                </h1>
                <ol class="breadcrumb">
                    <li>
                        <i class="fa fa-university"></i>  <a href="/courses">Courses</a>
                    </li>
                    <li>
                        <i class="fa fa-compass"></i> {{ course.title }}
                    </li>
                    <li class="active">
                        <i class="fa fa-star"></i> List Exams
                    </li>
                </ol>
            </div>
        </div>
        <!-- /.row -->
        
        <!-- Exams -->
        <div id="ajax_exams_table"
           name="ajax_exams_table">
            {% include "course/exam/exams_table.html" %}
        </div>
        <!-- /.row -->

<script>
    function ajax_refresh_exams_table()
    {
        $.ajax( 'exams_table', {
            data: {
               'csrfmiddlewaretoken': '{{ csrf_token }}',
            },
            type: 'post',
            success: function(result) {
               // success code execution here
               $('#ajax_exams_table').html(result); // Update UI.
            },
            error: function(xhr,status,error) {
               // error code here
            },
            complete: function(xhr,status) {
               // completion code here
            }
        });
    }
    
function ajax_delete_exam_submission(exam_id)
{
    $('#del_' + exam_id + '_btn').prop("disabled", true); // Lock button
    $.ajax( 'delete_exam', {
           data: {
                'csrfmiddlewaretoken': '{{ csrf_token }}',
                'exam_id': exam_id,
           },
           type: 'post',
           success: function(result) {
                // success code execution here
                if (result.status == 'success')
                {
                    ajax_refresh_exams_table(); // Reload UI.
                }
                else
                {
                    alert(result.message);
                }
           },
           error: function(xhr,status,error) {
                // error code here
           },
           complete: function(xhr,status) {
                // completion code here
                $('#del_' + exam_id + '_btn').prop("disabled", false); // Unlock button
           }
    });
}

/**
 *  Function will load up the exams view
 */
function view_exam(exam_id)
{
    window.location = "exam/" + exam_id;
}
</script>
{% endblock content %}